package com.wc.alorithm_blue_bridge._数学知识.约数.Q1260;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congege
 * @Description 最大公约数
 * https://www.lanqiao.cn/problems/1260/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=8
 * @Date Created in 2023/10/30-19:54
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        StringBuffer ans = new StringBuffer();
        Main main = new Main();
        while (n-- > 0) {
            int num1 = sc.nextInt();
            int num2 = sc.nextInt();
            ans.append(main.gcd(num1,num2));
            ans.append('\n');
        }

        System.out.print(ans);
    }

    public int gcd(int num1, int num2) {
        if (num1 > num2) {
            return gcd(num2, num1);
        }
        while (num2 % num1 != 0) {
            num2 = num2 % num1;
            num1 = num1 + num2;
            num2 = num1 - num2;
            num1 = num1 - num2;
        }

        return num1;
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
